<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search ref="search" :config="searchConfig" @search="search" @getHeight="getHeight"/>
    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-94'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config="tableToolbar"
       :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <!-- 操作按钮区域 -->
          <div class="table-operator">
            <a-button v-has="'carModelList:add'" @click='handleAdd'>新增</a-button>
            <a-button v-has="'carModelList:delete'" @click='batchDel'>删除</a-button>
            <a-button v-has="'carModelList:synchronization'"  @click=''>同步</a-button>
            <a-button v-has="'carModelList:export'"  @click=''>导出</a-button>
          </div>
        </template>
        <template #modelCode='{ row,rowIndex }'>
          <a @click="handleDetail(row)">{{ row.modelCode }}</a>
        </template>
        <template #action='{ row }'>
          <a v-has="'carModelList:update'" @click='handleEdit(row)'>编辑</a>
          <a-divider type='vertical' />
          <a v-has="'business:log'" href='javascript:' @click='handleBusiness("车型清单",row)'>日志</a>
        </template>
        <template #modelProperty='{ row }'>
          {{row.modelProperty == '1' ? '速冻' : '常温'}}
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <business-log ref='businessLog'></business-log>
    <car-model-list-model ref="modalForm" @ok="modalFormOk"></car-model-list-model>
  </a-card>
</template>

<script>
  import { PageListMixin } from '@/mixins/PageListMixin'
  import { getAction } from '@/api/manage'
  import carModelListModel from './modules/CarModelListModel.vue'
  //高级查询modal需要参数

  export default {
    name: 'carModelList',
    mixins: [PageListMixin],
    components: {
      carModelListModel,
    },
    // priceAdd
    data() {
      return {
        description: '经销商可购清单',
        //字典数组缓存
        sexDictOptions: [],
        importExcelUrl: `${window._CONFIG['domianURL']}/test/cn-formDemo/importExcel`,
        searchConfig:[
          {
            // label:'订单编号',
            type:'input',
            name:'modelCode',
            placeholder:'车型编号',
          },
          {
            type:'input',
            name:'modelName',
            placeholder:'车型名称',
          },
          {
            type:'input',
            name:'carLength',
            placeholder:'车长',
          },
          {

            type:'a-select',
            name:'modelProperty',
            option:[{
              name:'速冻',
              value:'1'
            },{
              name:'常温',
              value:'0'
            }],
            placeholder:'车型属性',
          }],
        //表头
        columns: [],
        //列设置
        settingColumns: [],
        //列定义  表格改这儿
        defColumns: [
          { type: 'checkbox', width: 60, fixed: 'left' },
          {
            fixed: 'left',
            title: '车型编号',
            minWidth: 80,
            field: 'modelCode',
            slots: { default: 'modelCode' },
            ellipsis:true,
          },
          {
            title: '车型名称',
            minWidth: 80,
            field: 'modelName'
          },
          {
            title: '最小体积',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'minVolume'
          },
          {
            title: '最大体积',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'maxVolume'
          },
          {
            title: '最小件数',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'minNumber'
          },
          {
            title: '最大件数',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'maxNumber'
          },
          {
            title: '车型属性',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'modelProperty',
            slots: { default: 'modelProperty' }
          },
          {
            title: '车长',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'carLength',
          },
          {
            title: '备注',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'remarks',
          },
          {
            title: '创建人',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'createName',
          },
          {
            title: '创建时间',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'createTime',
          },
          {
            title: '更新人',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'updateName',
          },
          {
            title: '更新时间',
            align: 'left',
            ellipsis:true,
            minWidth: 80,
            field: 'updateTime',
          },
          {
            title: '操作',
            field: 'action',
            fixed: 'right',
            align: 'center',
            ellipsis:true,
            minWidth: 120,
            slots: { default: 'action' }
          }
        ],
        url: {
          list: window._CONFIG['domianURL'] + '/modeldetailed/cnModelDetailed/findPageList',
          detail: window._CONFIG['domianURL'] + '/modeldetailed/cnModelDetailed/getInfo',
          deleteBatch: window._CONFIG['domianURL'] + '/modeldetailed/cnModelDetailed/deleteBatch',
          startOrStopUrl: window._CONFIG['domianURL'] + "/material/startOrStop",
          exportXlsUrl: '/test/cn-formDemo/exportXls'
        }

      }
    },
    methods: {
      startorstop: function(status) {
        if (!this.url.startOrStopUrl) {
          this.$message.error("请设置url启用停用!")
          return;
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');

        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          var that = this;
          this.$confirm({
            title: "确认修改",
            content: "是否修改选中数据?",
            onOk: function () {
              that.loading = true;
              getAction(that.url.startOrStopUrl, {ids: ids, status: status}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
        }
      },
      selectCusttype(value) {
        this.$set(this.queryParam, 'custType', value)
      },
      //跳转单据页面
      jump() {
        this.$notification.success('跳转 ： jump')
      },
      onBirthdayChange: function(value, dateString) {
        console.log(dateString[0], dateString[1])
        this.queryParam.birthday_begin = dateString[0]
        this.queryParam.birthday_end = dateString[1]
      },
      //列设置更改事件
      onColSettingsChange(checkedValues) {
        var key = this.$route.name + ':colsettings'
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues
        const cols = this.defColumns.filter(item => {
          if (item.key == 'rowIndex' || item.dataIndex == 'action') {
            return true
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns = cols
      },
      initColumns() {
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name + ':colsettings'
        let colSettings = Vue.ls.get(key)
        if (colSettings == null || colSettings == undefined) {
          let allSettingColumns = []
          this.defColumns.forEach(function(item, i, array) {
            allSettingColumns.push(item.dataIndex)
          })
          this.settingColumns = allSettingColumns
          this.columns = this.defColumns
        } else {
          this.settingColumns = colSettings
          const cols = this.defColumns.filter(item => {
            if (item.key == 'rowIndex' || item.dataIndex == 'action') {
              return true
            }
            if (colSettings.includes(item.dataIndex)) {
              return true
            }
            return false
          })
          this.columns = cols
        }
      }
    },
    created() {
      this.initColumns()
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>